package com.hr.builder;

import org.springframework.stereotype.Component;

import com.espirit.builder.biz.FormBuilderSupport;
import com.espirit.eap.pagelayout.Element;
import com.espirit.eap.pagelayout.ModelField;
import com.hr.HrSetting;
import com.hr.LeaveAppItem;

@Component
public class LeaveAppItemBuilder extends FormBuilderSupport {
	static final String HOURS = "hours";
	static final String BEGINTIME = "beginTime";
	static final String ENDTIME = "endTime";
	static final String LEAVETYPE = "leaveType";
	
	
	@Override
	public boolean init() {
		return super.setClass(LeaveAppItem.class, "Leave App Item", "请假清单");
	}

	@Override
	public void buildFields() {
		super.buildFields();
		addModelField(HOURS, "Hours(h)", "请假小时(h)");
		addModelField(BEGINTIME, "Begin", "开始时间");
		addModelField(ENDTIME, "End", "结束时间");
		addModelField(LEAVETYPE, "Leave Type", "类型");
	}
	
	@Override
	protected void addSearchFields() {
		super.addSearchField(convertPropertyToField(EMPLOYEE, DEPTIDS, LEAVETYPE, ENTITY_STATUS));
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(PROOF_NBR, ENTITY_STATUS, EMPLOYEE, LEAVETYPE,  BEGINTIME, ENDTIME, HOURS, REMARK, DEPARTMENT, CREATED, CREATED_ON ));
	}
	
	@Override
	protected void addDetailFields() {
		addDetailField(convertPropertyToField(EMPLOYEE, LEAVETYPE, BEGINTIME, ENDTIME, HOURS, REMARK));
	}
	
	@Override
	protected void gatherExproperties() {
		exProperties.put(REQUIRED, new String[]{EMPLOYEE, LEAVETYPE, BEGINTIME, ENDTIME, HOURS});
	}
	
	@Override
	protected Element convertFieldToElement(ModelField mf, boolean isListLayout) {
		Element element = super.convertFieldToElement(mf, isListLayout);
		String name = element.getName();
//		if (!isListLayout){
			if (BEGINTIME.equals(name) || ENDTIME.equals(name)){
				element.addExProperty("format", HrSetting.TIME_FORMAT);
			}
//		}
		return element;
	}
	
	@Override
	protected boolean addRelatedFiles() {
		return true;
	}
	
}
